/*
 * File Name：PayResultActivity.java
 * Copyright：Copyright 2008-2014 CiWong.Inc. All Rights Reserved.
 * Description： PayResultActivity.java
 * Modify By：bin
 * Modify Date：2014年4月8日
 * Modify Type：Add
 */
package com.ciwong.mobilepay.ui;

import android.graphics.drawable.Drawable;
import android.support.v4.content.res.ResourcesCompat;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.TextView;

import com.ciwong.mobilelib.R;
import com.ciwong.mobilepay.bean.PayDetail;
import com.ciwong.mobilepay.util.PayUtil;
import com.ciwong.mobilepay.view.PayResult;

/**
 * 支付结果Activity
 * 
 * @author bin
 * @version ciwong v.1.0 2014年4月8日
 * @since ciwong v.1.0
 */
public class PayResultActivity extends MPBaseActivity
{
    private int result;

    private PayDetail mPayDetail;

    private TextView payResult, payResultCommodityName,
            payResultCommodityNumber;

    private Button payResultComplete;

    @Override
    public void preCreate()
    {
        super.preCreate();
        setForbiddenTitleBar(true);
        result = ((PayStatusActivity) getParent()).getResult();
        mPayDetail = ((PayStatusActivity) getParent()).getPayDetail();
    }

    @Override
    protected View setView()
    {
        return new PayResult(this);
    }

    @Override
    protected void findViews()
    {
        payResult = (TextView) findViewById(PayResult.payResult);
        payResultCommodityName = (TextView) findViewById(PayResult.payResultCommodityName);
        payResultCommodityNumber = (TextView) findViewById(PayResult.payResultCommodityNumber);
        payResultComplete = (Button) findViewById(PayResult.payResultComplete);
    }

    @Override
    protected void initEvent()
    {
        payResultComplete.setOnClickListener(new OnClickListener()
        {
            @Override
            public void onClick(View v)
            {
                ((PayStatusActivity) getParent()).setResult();
            }
        });
    }

    @Override
    protected void init()
    {
        // mPayDetail = new PayDetail();
        // mPayDetail.setName("ssss");
        // mPayDetail.setNumber(1);
        // result = 0;
        if (mPayDetail != null)
        {
            payResultCommodityName.setText(String.format("商品名称:%s",
                    mPayDetail.getName()));
            payResultCommodityNumber.setText(String.format("商品数量:%s",
                    mPayDetail.getNumber()));
        }
        if (result == 0)
        {
            payResult.setText("恭喜你!购买成功");
            Drawable celebrateSuccess = ResourcesCompat.getDrawable(getResources(), R.mipmap.celebrate_success,null);
            payResult.setCompoundDrawablesWithIntrinsicBounds(celebrateSuccess,
                    null, null, null);
            payResultComplete.setText("完成");
        }
        else
        {
            payResult.setText("Sorry!购买失败");
            Drawable sorryFail = ResourcesCompat.getDrawable(getResources(), R.mipmap.celebrate_success,null);
            payResultComplete.setText("重新购买");
            payResult.setCompoundDrawablesWithIntrinsicBounds(sorryFail, null,
                    null, null);
        }
    }

    @Override
    protected void loadData()
    {

    }
}
